<template>
	<view>
		<swiper :autoplay="true" :indicator-dots="true" :interval="3000" :duration="1000" :circular="true">
			<swiper-item v-for="item in banners" :key="item.goods_id">
				<view class="swiper-item">
					<image :src="item.image_src" @click="goToDetail(item.goods_id)"></image>
				</view>
			</swiper-item>
		</swiper>
		<view class="nav-list">
		   <view class="nav-item" v-for="(item, index) in cateList" :key="index">
		     <image :src="item.image_src" class="nav-img" @click="goJump(item)"></image>
		   </view>
		</view>
		<!-- 楼层 item 项 -->
		        <view class="floor-item" v-for="(item,index) in floors" :key="index">
		          <!-- 标题部分 -->
		          <image :src="item.floor_title.image_src" class="floor-title"></image>
		          <!-- 标题下图片区域 -->
		          <view class="floor-img-box">
		            <!-- 左侧大图片的盒子 -->
		            <navigator url="/subpkj/goods_list/goods_list" class="left-img-box">
		              <image class="left-img" :src="item.product_list[0].image_src" :style="{
		                width:item.product_list[0].image_width+'rpx'
		              }"></image>
		            </navigator>
		            <!-- 右侧 4 个小图片的盒子 -->
		            <view class="right-img-box">
		              <view class="right-img-item" v-for="(item2, i2) in item.product_list" :key="i2" v-if="i2 > 0">
		                <image :src="item2.image_src" :style="{
		                width:item2.image_width+'rpx'
		              }" mode="widthFix"></image>
		              </view>
		            </view>
		          </view>
		        </view>
	</view>
</template>

<script>
	import {getBanners,getCates,getFloors} from '@/api/home.js'
	import toast from '@/untils/toast.js'
	export default {
		data() {
			return {
				banners:[],
				cateList:[],
				floors:[]
			};
		},
		onLoad() {
			this.getBanners()
			this.getCates()
			this.getFloors()
		},
		methods:{
			async getBanners(){
				const {message} = await getBanners()
				this.banners = message
				toast.success({
					title:'跳转成功'
				})
			},
			goToDetail(id){
				uni.navigateTo({
					url:`/subpkj/goods_detail/goods_detail?id=${id}`
				})
			},
			async getCates(){
				const {message} = await getCates()
				console.log('message',message)
				this.cateList = message
			},
			goJump(item){
				if(item.name==='分类'){
					uni.switchTab({
						url:'/pages/cate/cate'
					})
				}
			},
			async getFloors(){
				const {message} = await getFloors()
				this.floors = message
			}
		}
	}
</script>

<style lang="scss">
swiper {
 height: 330rpx;

 .swiper-item,
 image {
   width: 100%;
   height: 100%;
 }
}
.nav-list {
  display: flex;
  justify-content: space-around;
  margin: 15px 0;

  .nav-img {
    width: 128rpx;
    height: 140rpx;
  }
}
.floor-title {
  height: 60rpx;
  width: 100%;
  display: flex;
}
.right-img-box {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
}

.floor-img-box {
  display: flex;
  padding-left: 10rpx;
 .left-img {
  height: 392rpx !important;
 }
}
</style>
